home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 215 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.7 KB  |  113 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Are all Windows programs ill-formed?
  5. Date: 01 Feb 1996 09:07:11 PST
  6. Organization: Computer Science, University of Melbourne, Australia
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <9602010236.26117@mulga.cs.mu.OZ.AU>
  9. References: <AE5J83na99@qsar.chem.msu.su>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. Summary: yes, almost all of them are ill-formed
  12. X-Original-Date: Thu, 1 Feb 1996 13:36:58 +1100
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMRDzUky4NqrwXLNJAQGgfQIAgn14/VwhL+H8aqX5l8o1hW1sXD4bxiZC
  15.     lsDWDl6k1zLockoMBRvek0Te2X3j2uoWyWQLQxssPVgDelXUzhS4WA==
  16.     =eYgs
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. "Eugene Radchenko" <eugene@qsar.chem.msu.su> writes:
  20.  
  21. >I have just realized that something is grossly overlooked in C++ standard.
  22.  
  23. I think the problem is due to Microsoft overlooking the C and C++
  24. standards, not vice versa.
  25.  
  26. >It requires every program to have the main() function (which implementation
  27. >is not allowed to supply) with parameters (void) or (int argc, int*argv[]).
  28.  
  29. The implementation is allowed to make the program work even if main() is
  30. not defined, so long as it issues a diagnostic.
  31.  
  32. >However, Windows programs have another convention: prrogram must contain
  33. >the function
  34. >  int WinMain(HINSTANCE curInst, HINSTANCE prevInst, LPSTR cmdline, int cmdShow)
  35.  
  36. A compiler is allowed to accept the program
  37.  
  38.     int WinMain(HINSTANCE curInst, HINSTANCE prevInst, LPSTR cmdline,
  39.         int cmdShow)
  40.     {
  41.         return 0;
  42.     }
  43.  
  44. so long as it issues at least one diagnostic, e.g.
  45. "warning: standard C++ requires a definition of main()".
  46.  
  47. But if a compiler does not accept
  48.  
  49.     int main() { return 0; }
  50.  
  51. as a complete program, then that compiler is not a conforming C or C++
  52. implementation.
  53.  
  54. >Some of this is of course quirks or even outright ignored in Win32
  55. >(prevInst), but the full non-parsed command line could be useful sometimes,
  56. >and not all implementations provide the function retrieving it.
  57.  
  58. In many operating systems, the command-line parsing is done by the
  59. shell, not the OS.  Such operating systems cannot provide the non-parsed
  60. command line.
  61.  
  62. >And anyway this is definitely not a main() from the specs.
  63. >Maybe the requirements on the main() should be relaxed somehow?
  64.  
  65. Are you suggesting relaxing the requirements on implementations,
  66. or the requirements on programs?
  67.  
  68. I presume you are referring to 3.6.1[basic.start.main]/1:
  69.  
  70. |    A program shall contain a global function called main, which is the
  71. |    designated start of the program.
  72.  
  73. You are correct to infer that this means that all Windows programs
  74. which do not define main() are ill-formed.
  75.  
  76. However, that means only that a compiler is required to issue
  77. a diagnostic; it does not mean that the compiler must reject the
  78. program.
  79.  
  80. Obviously a program that does not define main() is not going to be
  81. portable, so I don't think that requirement on programs should be
  82. relaxed.
  83.  
  84. Windows compilers which wish to conform to the C and C++ standards
  85. should include code similar to
  86.  
  87.     HINSTANCE __curInst;
  88.     HINSTANCE __prevInst;
  89.     LPSTR __cmdline;
  90.     int WinMain(HINSTANCE curInst, HINSTANCE prevInst, LPSTR cmdline,
  91.         int cmdShow)
  92.     {
  93.         int argc;
  94.         char **argv;
  95.  
  96.         __curInst = curInst;
  97.         __prevInst = prevInst;
  98.         __cmdLind = cmdLine;
  99.         __parse_command_line(cmdline, &argc, &argv);
  100.         return main(argc, argv);
  101.     }
  102.  
  103. in their libraries, so that they can accept programs which define main()
  104. but not WinMain().
  105.  
  106. --
  107. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  108. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  109. ---
  110. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  111.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  112.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  113.